package com.cskaoyan.controller.mall;

import com.cskaoyan.bean.common.BasePageInfo;
import com.cskaoyan.bean.common.BaseRespVo;
import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.bean.po.MarketKeyword;
import com.cskaoyan.service.mall.MallKeywordListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("admin/keyword")
public class MallKeywordListController {

    @Autowired
    MallKeywordListService mallKeywordListService;

    @RequestMapping("list")
    public BaseRespVo queryMallKeywordList(BasePageInfo basePageInfo, String keyword, String url) {
        CommonData<MarketKeyword> commonData = mallKeywordListService.queryMallKeywordList(basePageInfo, keyword, url);
        return BaseRespVo.succeed(commonData);
    }

    @RequestMapping("create")
    public BaseRespVo createMallKeyword(@RequestBody MarketKeyword marketKeyword) {
        MarketKeyword marketKeyword1 = mallKeywordListService.createMallKeyword(marketKeyword);
        if (marketKeyword1 == null) {
            BaseRespVo.invalidParameter("添加失败！请重试！");
        }
        return BaseRespVo.succeed(marketKeyword1);
    }

    @RequestMapping("update")
    public BaseRespVo updateMallKeyword(@RequestBody MarketKeyword marketKeyword) {
        MarketKeyword marketKeyword1 = mallKeywordListService.updateMallKeyword(marketKeyword);
        if (marketKeyword1 == null) {
            BaseRespVo.invalidParameter("修改失败！请重试！");
        }
        return BaseRespVo.succeed(marketKeyword1);
    }

    @RequestMapping("delete")
    public BaseRespVo deleteMallKeyword(@RequestBody MarketKeyword marketKeyword) {
        int code = mallKeywordListService.deleteMallKeyword(marketKeyword.getId());
        if (code == 0) {
            BaseRespVo.invalidParameter("删除失败！请重试！");
        }
        return BaseRespVo.succeed();
    }

}
